let us=new Vue({
    el:'#user-list',
    data:{
        users:[]
    },
    created(){
        // 查询所有用户
        $.get('http://localhost:8080/cinema/api/UserListServlet.do', function (dto) {
            us.users = dto.value;
        });
    },
    methods:{
        selectByLike:function(){
            let formData={
                cond:$("#cond").val()
            }
            // 发送异步 ，实现放映计划的模糊查询
            $.get('http://localhost:8080/cinema/api/SelectUsersByLikeServlet.do',formData,function(dto){
                console.log(dto.value);
                us.users=dto.value;
            });
        },
        dongjie:function(id){
            layer.confirm('确定要冻结此账号嘛？', {skin: 'layui-layer-molv',icon:3,title:'提示',
                btn: ['是的', '取消']
            }, function () {

                let formData = {
                    userId: id,
                    status:2
                }

                $.ajax({
                    url:'http://localhost:8080/cinema/api/UpdateUserStatusServlet.do',
                    type:'put',
                    data:JSON.stringify(formData),
                    dataType:'json',
                    success:function(dto){
                        if(dto.code==200){
                            // 刷新
                            $.get('http://localhost:8080/cinema/api/UserListServlet.do', function (dto) {
                                us.users = dto.value;
                            });
                            layer.msg("已冻结",{icon:1});
                            
                        }else{
                            layer.msg("冻结失败",{icon:2});
                        }
                    }
                });

            }, function () {

            });
        },
        jiefeng:function(id){
            layer.confirm('确定要解封此账号嘛？', {skin: 'layui-layer-molv',icon:3,title:'提示',
                btn: ['是的', '取消']
            }, function () {
                let formData = {
                    userId: id,
                    status:1
                }

                $.ajax({
                    url:'http://localhost:8080/cinema/api/UpdateUserStatusServlet.do',
                    type:'put',
                    data:JSON.stringify(formData),
                    dataType:'json',
                    success:function(dto){
                        if(dto.code==200){
                            // 刷新
                            $.get('http://localhost:8080/cinema/api/UserListServlet.do', function (dto) {
                                us.users = dto.value;
                            });
                            layer.msg("已解封",{icon:1});
                            
                        }else{
                            layer.msg("解封失败",{icon:2});
                        }
                    }
                });

            }, function () {

            });
        }
            
    }
});